OPC Studio User's Guide and Reference
TryGetValue Method (IKeyedCollection<TKey,TItem>)



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.Collections.Generic Namespace > IKeyedCollection<TKey,TItem> Interface : TryGetValue Method
The key of the item to search in the collection.

The value of this parameter cannot be null (Nothing in Visual Basic).

When this method returns true, the item from the collection that matches the provided key; when this method returns false, the default value for the type of the collection.

The value of this parameter can be null (Nothing in Visual Basic).

Tries to get an item from the collection using the specified key.
Syntax
'Declaration
 
Function TryGetValue( _
   ByVal key As TKey, _
   ByRef item As TItem _
) As Boolean
'Usage
 
Dim instance As IKeyedCollection(Of TKey,TItem)
Dim key As TKey
Dim item As TItem
Dim value As Boolean
 
value = instance.TryGetValue(key, item)
bool TryGetValue( 
   TKey key,
   out TItem item
)
bool TryGetValue( 
   TKey^ key,
   [Out] TItem^ item
) 

Parameters

key
The key of the item to search in the collection.

The value of this parameter cannot be null (Nothing in Visual Basic).

item
When this method returns true, the item from the collection that matches the provided key; when this method returns false, the default value for the type of the collection.

The value of this parameter can be null (Nothing in Visual Basic).

Return Value

true if an item for the specified key was found in the collection; otherwise, false.
Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also